<?php

use console\services\MigrateService;
use yii\db\Migration;

/**
 * Handles the creation of table `sys_config`.
 */
class m231229_144105_create_sys_config_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('sys_config', [
            'id' => $this->bigPrimaryKey(),
            'name' => $this->string(64)->defaultValue('')->notNull()->comment('配置名称'),
            'config_key' => $this->string(64)->defaultValue('')->notNull()->unique()->comment('配置标识'),
            'type' => $this->string(64)->defaultValue('')->notNull()->comment('配置类型'),
            'groups' => $this->string(64)->defaultValue('')->notNull()->comment('配置分组'),
            'is_sys' => $this->char(1)->defaultValue('0')->notNull()->comment('是否系统内置'),
            'value' => $this->text()->null()->comment('配置值'),
            'list_sort' => $this->bigInteger()->defaultValue(10)->null()->comment('排序'),
            'remark' => $this->string(255)->defaultValue('')->null()->comment('说明'),
            'create_time' => $this->bigInteger()->defaultValue(0)->null()->comment('创建时间'),
            'update_time' => $this->bigInteger()->defaultValue(0)->null()->comment('更新时间'),
        ], MigrateService::createTableOptions('参数配置表'));

        $this->batchInsert('sys_config',
            ['id', 'name', 'config_key', 'type', 'groups', 'is_sys', 'value', 'list_sort'],
            [
                [1, '配置分组', 'sys.conf.group', 'text', '系统设置', '1', '系统设置;短信配置;邮箱配置', 1],
                [2, '系统名称', 'sys.conf.sysName', 'text', '系统设置', '1', 'B5YiiCMF', 2],
                [3, '账户初始密码', 'sys.user.pwd', 'text', '系统设置', '1', '123456', 10],
                [4, '系统图标', 'sys.conf.logo', 'file', '系统设置', '1', '', 4],
            ]
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('sys_config');
    }
}
